<template>
  <div
    class="app-container flex flex-sub"
    style="background: none; height: 100%; padding: 1rem"
  >
    <el-card shadow="never" class="box-card flex-sub" style="overflow: auto">
      <div class="div-query">
        <div class="collapse">
          <div class="collapse-header" @click="panelActive = !panelActive">
            <i
              class="collapse-header-icon"
              :class="[
                panelActive ? 'el-icon-caret-bottom' : 'el-icon-caret-top',
              ]"
            />
            {{ panelActive ? '隐藏' : '展开' }}查询条件
          </div>
          <div class="collapse-content">
            <el-collapse-transition>
              <div v-show="panelActive">
                <el-form size="small" label-position="right">
                  <el-row>
                    <el-col :span="8">
                      <el-form-item label="健康码" label-width="120px">
                        <el-select
                          v-model="searchModel.healthCode"
                          placeholder="选择健康码"
                          clearable
                          filterable
                        >
                          <el-option
                            v-for="item in healthCodeList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                          />
                        </el-select>
                      </el-form-item>
                    </el-col>

                    <el-col :span="8">
                      <el-form-item label="场所名称" label-width="120px">
                        <!-- <el-input
                          v-model="searchModel.placeName"
                          placeholder="输入场所名称"
                          clearable
                          class="filter-item search-item"
                        /> -->
                        <el-select
                          v-model="searchModel.placeName"
                          placeholder="选择场所名称"
                          clearable
                          filterable
                        >
                          <el-option
                            v-for="item in placeList"
                            :key="item.placeName"
                            :label="item.placeName"
                            :value="item.placeName"
                          />
                        </el-select>
                      </el-form-item>
                    </el-col>
                    <el-col :span="8">
                      <el-form-item label="检测设备" label-width="120px">
                        <!-- <el-input
                          v-model="searchModel.deviceName"
                          placeholder="输入检测设备"
                          clearable
                          class="filter-item search-item"
                        /> -->
                        <el-select
                          v-model="searchModel.deviceName"
                          placeholder="选择检测设备"
                          clearable
                          filterable
                        >
                          <el-option
                            v-for="item in deviceList"
                            :key="item.deviceName"
                            :label="item.deviceName"
                            :value="item.deviceName"
                          />
                        </el-select>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="8">
                      <el-form-item label="核酸检测结果" label-width="120px">
                        <el-select
                          v-model="searchModel.nucleicAcidResult"
                          placeholder="选择核酸检测结果"
                          clearable
                          filterable
                        >
                          <el-option
                            v-for="item in nucleicAcidResultList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                          />
                        </el-select>
                      </el-form-item>
                    </el-col>

                    <el-col :span="8" style="margin-left: 10px">
                      <el-form-item>
                        <el-button
                          type="primary"
                          icon="el-icon-search"
                          @click="toSearch"
                          style="margin-right: 10px"
                          >搜索</el-button
                        >
                        <el-button
                          type="info"
                          icon="el-icon-delete"
                          @click="toReset"
                          style="margin-right: 10px"
                          >重置</el-button
                        >
                        <el-button size="small" @click="getDataList">
                          <i class="el-icon-refresh" style="color: #606266" />
                          <span style="color: #606266">刷新</span>
                        </el-button>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form>
              </div>
            </el-collapse-transition>
          </div>
        </div>
      </div>

      <div style="margin-bottom: 1rem">
        <el-button
          size="small"
          type="primary"
          style="margin-right: 20px"
          @click="exportExcel"
        >
          <i
            class="el-icon-download"
            style="font-size: 13px; margin-right: 5px"
          />导出
        </el-button>
      </div>

      <div>
        <el-table
          ref="elTable"
          v-loading="loading || deleteLoading"
          border
          fit
          size="medium "
          :data="dataList"
          :row-key="(row) => row.id"
          style="width: 100%"
          :element-loading-text="deleteLoading ? '删除中,请等待...' : ''"
          @sort-change="onSortChange"
          @selection-change="onSelectionChange"
        >
          <el-table-column
            align="center"
            type="index"
            width="50"
            fixed
            label="#"
            :index="indexMethod"
          />
          <af-table-column
            align="center"
            label="人脸抓拍照"
            prop="facecapture"
            width="100"
          >
            <template slot-scope="{ row }">
              <img
                :src="row.facecapture"
                style="width: 40px; height: 40px; cursor: pointer"
                @click="handleImgPreview(row.facecapture)"
              />
            </template>
          </af-table-column>
          <af-table-column align="center" label="姓名" prop="name" width="80" />
          <af-table-column
            align="center"
            label="身份证号"
            prop="sfzh"
            width="180"
          />

          <af-table-column align="center" label="场所名称" prop="placeName" />
          <af-table-column
            align="center"
            label="出入场时间"
            prop="inOutTime"
            width="150"
          />
          <af-table-column
            align="center"
            label="健康码"
            prop="healthCode"
            width="80"
          >
            <template slot-scope="{ row }">
              <el-tag
                size="medium"
                :style="row.healthCode | constantKeyTagStyleObj('HEALTH_CODE')"
              >
                {{ row.healthCode | constantKeyValue('HEALTH_CODE') }}
              </el-tag>
            </template>
          </af-table-column>
          <af-table-column
            align="center"
            label="体温"
            prop="temperature"
            width="80"
          >
            <template slot-scope="{ row }">
              <el-tag
                size="medium"
                :type="row.temperature < 37.2 ? 'success' : 'warning'"
              >
                {{ row.temperature }}℃
              </el-tag>
            </template>
          </af-table-column>
          <af-table-column align="center" label="行程卡信息" prop="tripPath" />
          <af-table-column
            align="center"
            label="核酸检测结果"
            prop="nucleicAcidResult"
            width="120"
          >
            <template slot-scope="{ row }">
              <el-tag
                size="medium"
                :style="
                  row.nucleicAcidResult
                    | constantKeyTagStyleObj('NUCLEIC_ACID_RESULT')
                "
              >
                {{
                  row.nucleicAcidResult
                    | constantKeyValue('NUCLEIC_ACID_RESULT')
                }}
              </el-tag>
            </template>
          </af-table-column>
          <af-table-column
            align="center"
            label="核酸检测时间"
            prop="nucleicAcidTime"
            width="150"
          />
          <af-table-column align="center" label="检测设备" prop="deviceName" />
          <af-table-column
            align="center"
            label="核验方式"
            prop="verificationMode"
            width="80"
          >
            <template slot-scope="{ row }">
              {{ globalConstant.VERIFICATION_MODE[row.verificationMode].text }}
            </template>
          </af-table-column>

          <af-table-column
            align="center"
            label="操作区"
            fixed="right"
            width="120"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="{ row }">
              <el-tooltip effect="dark" content="详情" placement="top-start">
                <i
                  class="iconfont icon-chakanxiangqing2 i-detail"
                  @click="toDetail(row)"
                />
              </el-tooltip>
            </template>
          </af-table-column>
        </el-table>
        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="pagination.pageNum"
          :limit.sync="pagination.pageSize"
          :page-sizes="pageSizeOptions"
          @pagination="getDataList"
        />
      </div>
    </el-card>

    <el-dialog
      :visible.sync="imgDialogVisible"
      :title="'人脸抓拍照片'"
      top="120px"
      width="500px"
    >
      <img :src="dialogImageUrl" alt="" style="padding: 20px; width: 100%" />
    </el-dialog>

    <alarm-records-detail
      ref="detailDialog"
      :dialog-visible="detailDialogObj.isVisible"
      :title="detailDialogObj.title"
      :params="params"
      @close="dialogClose('detailDialogObj')"
      v-if="detailDialogObj.isVisible"
    />
  </div>
</template>
<script>
import Pagination from '@/components/Pagination'
import dataTableMixins from '@/mixins/data-table-mixins'
import EpidemicPreventionManageApi from '@/api/epidemic-prevention-manage'
import AlarmRecordsDetail from './component/Detail'
import globalConstant from '@/utils/constants'

export default {
  components: {
    Pagination,
    AlarmRecordsDetail,
  },
  mixins: [dataTableMixins],
  data() {
    return {
      deleteLoading: false,
      healthCodeList: [
        {
          label: '绿码',
          value: 0,
        },
        {
          label: '黄码',
          value: 1,
        },
        {
          label: '红码',
          value: 2,
        },
      ],
      nucleicAcidResultList: [
        {
          label: '阴性',
          value: 0,
        },
        {
          label: '阳性',
          value: 1,
        },
      ],
      imgDialogVisible: false,
      dialogImageUrl: '',

      deviceList: [],
      placeList: [],
    }
  },
  computed: {
    globalConstant() {
      return { ...globalConstant }
    },
  },
  mounted() {
    this.getPlaceList()
    this.getDeviceList()

    this.getDataList()
  },
  methods: {
    getPlaceList() {
      EpidemicPreventionManageApi.getAllPlaces().then((res) => {
        if (res.data.code == 200) {
          this.placeList = res.data.data
        }
      })
    },
    getDeviceList() {
      EpidemicPreventionManageApi.getAllDevice().then((res) => {
        if (res.data.code == 200) {
          this.deviceList = res.data.data
        }
      })
    },
    getDataList() {
      this.loading = true
      const searchModel = this.formatSearchData(this.searchModel)
      EpidemicPreventionManageApi.getAlertlist({
        ...this.pagination,
        ...searchModel,
        ...this.sort,
      })
        .then((res) => {
          if (res.data.code == 200) {
            this.dataList = res.data.data.rows
            this.total = res.data.data.total
            this.loading = false
          }
        })
        .catch(() => {
          this.loading = false
          this.dataList = []
          this.total = 0
        })
    },
    toSearch() {
      this.pagination.pageNum = 1
      this.getDataList()
    },
    toReset() {
      this.searchModel = {}
      this.sort = {}
      this.$refs.elTable.clearSort()
      this.$refs.elTable.clearFilter()
      this.toSearch()
    },
    onSortChange(val) {
      this.sort.field = val.prop
      this.sort.order = val.order
      this.toSearch()
    },
    onSelectionChange(selection) {
      this.selectedDataList = selection
    },
    toEmptySelection() {
      this.$refs.elTable.clearSelection()
    },
    indexMethod(index) {
      return this.formatIndex(index, this.pagination)
    },

    toDetail(data) {
      this.params = {
        item: data,
      }
      this.detailDialogObj.title = '防疫管理 ＞告警记录  ＞详情'
      this.detailDialogObj.isVisible = true
    },

    exportExcel() {
      const searchModel = this.formatSearchData(this.searchModel)
      EpidemicPreventionManageApi.downLoadAlertRecord(
        searchModel,
        `告警记录_${new Date().getTime()}.xlsx`
      ).then((ret) => {})
    },

    handleImgPreview(url) {
      this.dialogImageUrl = url
      this.imgDialogVisible = true
    },
  },
}
</script>


<style lang="scss"  scoped>
@import '../../../../styles/part-custom';
</style>